# coding: utf8
# models/plugin_plugin.py
## This file was created using static/plugin_plugin/model_template using the plugin_plugin
# copyright Christopher Steel, 2011, Voice of Access
#########################################
# initialization.py
import os
cwd = os.getcwd()
current_app = os.path.join(cwd,'applications',request.application)
initialization_file_path = os.path.join(current_app,'models','000_uc_initialization.py')

#################################################
if not 'plugin_font_blackout_installed' in globals():
    ####################################
    # do we hav an initialization file?
    #
    if not 'initialization_file_created' in globals():
        if not os.path.exists(initialization_file_path):
            our_file = open(initialization_file_path,"w")
            our_text = '# file created by plugin_font_blackout\n'
            our_text += 'initialization_file_created = True\n'
            our_file.writelines(our_text)
            our_file.close()
            print('created %s' % initialization_file_path)
        else:
            print('found %s' % initialization_file_path)
    else:
        print('found "initialization_file_created" in globals')
    #################################################################
    # Ensure we have any dependency plugins installed
    #
    #if not 'plugin_plugin_installed' in globals():
    #    our_file = open(initialization_file_path,"a")
    #    our_text = 'plugin_plugin_installed = True\n'
    #    our_file.write(our_text)
    #    our_file.close()
    #else:
    #    print('found plugin_plugin_installed in globals')
    ###############################################
    # ensure we have an admin group for our plugin
    #
    if not 'group_plugin_font_blackout_admin_created' in globals():
        if not db(db.auth_group.role=='plugin_font_blackout_admin').select(): 
            db.auth_group.insert(role='plugin_font_blackout_admin',description='user to administer plugin_font_blackout')
            our_file = open(initialization_file_path,"a")
            our_text = '# entry created by plugin_font_blackout\n'
            our_text += 'group_plugin_font_blackout_admin_created = True\n'
            our_file.write(our_text)
            our_file.close()
        else:
            print("found db.auth_group.role=='admin_plugin_plugin' in database")
    else:
        print('found "group_plugin_font_blackout_admin_created" globals')
    ###############################################
    # ensure we have an config group for our plugin
    #
    if not 'group_plugin_font_blackout_config_created' in globals():
        if not db(db.auth_group.role=='plugin_font_blackout_config').select(): 
            db.auth_group.insert(role='plugin_font_blackout_config',description='user to configure plugin_font_blackout')
            our_file = open(initialization_file_path,"a")
            our_text = '# entry created by plugin_font_blackout\n'
            our_text += 'group_plugin_font_blackout_config_created = True\n'
            our_file.write(our_text)
            our_file.close()
        else:
            print("found db.auth_group.role=='config_plugin_plugin' in database")
    else:
        print('found "group_plugin_font_blackout_config_created" globals')
    #################################################################
    # Ensure we have the global variable 'plugin_font_blackout_installed'
    #
    if not 'plugin_font_blackout_installed' in globals():
        our_file = open(initialization_file_path,"a")
        our_text = '# entry created by plugin_font_blackout\n'
        our_text += 'plugin_font_blackout_installed = True\n'
        our_file.write(our_text)
        our_file.close()
    else:
        print('models/plugin_font_blackout/initialization.py found')
        print('plugin_font_blackout_installed globals')
    #########################################
    # advertise that our plugin is available
    plugin_font_blackout_installed = True

###############
# plugin menus
#
response.menu+= [
    (T('plugin_font_blackout'), False, URL('plugin_font_blackout','index'),
        [
            (T('plugin options'), False, URL('plugin_font_blackout','index'),
                [
                    (T('option_1'), False, URL('plugin_font_blackout', 'option_1')),
                ]),
            (T('about'), False, URL(request.application,'plugin_font_blackout','display_static',args='about')),
            (T('contribute'), False, URL(request.application,'plugin_font_blackout','display_static',args='contribute')),  
            (T('license'), False, URL(request.application,'plugin_font_blackout','display_static',args='license')),
            (T('universal cake'), False, URL(request.application,'plugin_font_blackout','display_static',args='universal_cake')),
            (T('voice of access'), False, URL(request.application,'plugin_font_blackout','display_static',args='voice_of_access')),
        ]
   )]

##############################################
# site plugin_plugin users menu
#
# plugin_font_blackout menu is displayed to users who are signed in
if auth.is_logged_in():
    response.menu+= [    
    (T('plugin_font_blackout user menu'), False, URL('plugin_font_blackout','index'),
        [
            (T('plugin_font_blackout user actions'), False, URL('plugin_font_blackout','index'),
                [
                    (T('configure plugin_font_blackout'), False, URL('plugin_font_blackout', 'configure')),
                ]),          
        ]
   )]    

##############################################
# site plugin_plugin administrators menu
#
# plugin_font_blackout menu is displayed to registered signed in users who
# are also members of the admin_plugin_plugin group.
if auth.is_logged_in() and auth.has_membership(auth.id_group('admin_plugin_font_blackout')):
#        response.menu_admin_plugin = []
#        response.menu_admin_plugin += [
    response.menu+= [    
        ('plugin_font_blackout admin', False, URL('plugin_font_blackout','admin'),
       )]
#        response.menu_plugin += response.menu_admin_plugin
